package com.edgar.plugin.utils;

import android.util.Log;

/**
 * Created by Edgar on 2018/2/1.
 */
public final class ClassUtils {

    private static final String TAG = "ReflectUtils";

    private ClassUtils(){}

    public static Class<?> loadClass(ClassLoader classLoader,String className){
        try {
            return classLoader.loadClass(className);
        } catch (ClassNotFoundException e) {
            String msg = String.format("%s not found",className);
            Log.d(TAG,msg,e);
        }
        return null;
    }

    public static Class<?> loadClass(String className){
        try {
            return Class.forName(className);
        } catch (ClassNotFoundException e) {
            String msg = String.format("%s not found",className);
            Log.d(TAG,msg,e);
        }
        return null;
    }

    public static <T> T newInstance(Class<T> clazz){
        try {
            return clazz.newInstance();
        } catch (InstantiationException e) {
            Log.e(TAG,"New instance error",e);
        } catch (IllegalAccessException e) {
            Log.e(TAG,"Illegal access error",e);
        }
        return null;
    }
}